/*
 * @Author: xiaosihan
 * @Date: 2024-08-04 23:27:56
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-09-22 23:06:40
 */

import projectCollaborationApi from "@api/projectCollaborationApi";
import { get } from "lodash";
import { configure, observable } from "mobx";
configure({ enforceActions: "never" });

const projectJoinerStore = observable({
  // 项目id
  projectId: "",
  setProjectId(projectId: string = "") {
    this.projectId = projectId;
    this.page = 1;
    this.getList();
  },
  //当前页面
  page: 1,
  setPage(page: number) {
    this.page = page;
    this.getList();
  },
  //分页数
  pageSize: 10,
  setPageSize(pageSize: number) {
    this.pageSize = pageSize;
    this.getList();
  },
  //总数
  totalCount: 0,
  setTotalCount(totalCount: number) {
    this.totalCount = totalCount;
  },
  //数据列表
  list: [] as Array<any>,
  setList(list: Array<any>) {
    this.list = list;
  },
  //请求数据
  async getList() {
    const { page, pageSize } = this;
    const result = await projectCollaborationApi.getJoinerList(
      page,
      pageSize,
      this.projectId
    );
    const list = get(result, ["data", "data"]) as Array<any>;
    this.totalCount = Number(get(result, ["data", "totalCount"]));
    this.setList(list);
  },

  //删除项目成员
  async delete(id: string) {
    await projectCollaborationApi.deleteJoiner(id);
    // 删除完后请求数据
    this.getList();
  },
});
export default projectJoinerStore;
